package com.dahuyou.tryy.too.simulate.interpreter.parse.clazz.clazzfile.constantpool.item;

import com.dahuyou.tryy.too.simulate.interpreter.parse.clazz.clazzfile.ClassReader;
import com.dahuyou.tryy.too.simulate.interpreter.parse.clazz.clazzfile.constantpool.ConstantInfo;
import com.dahuyou.tryy.too.simulate.interpreter.parse.clazz.clazzfile.constantpool.ConstantPool;

public class ConstantStringInfo implements ConstantInfo {

    private ConstantPool constantPool;
    private int strIdx;

    public ConstantStringInfo(ConstantPool constantPool) {
        this.constantPool = constantPool;
    }

    @Override
    public void readInfo(ClassReader reader) {
//        this.strIdx = reader.readUint16();
        this.strIdx = reader.readU2();
    }

    @Override
    public int tag() {
        return this.CONSTANT_TAG_STRING;
    }

    public String string(){
        return this.constantPool.getUTF8(this.strIdx);
    }

    @Override
    public void showInfo() {
        System.out.println("tag 是：" + this.tag() + ", string 常量值是：" + this.string());
    }
}
